home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJSRC106.ARJ / AOUT2EXE.C < prev    next >
C/C++ Source or Header  |  1992-04-13  |  1KB  |  58 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <sys/stat.h>
  4. #include <alloc.h>
  5.  
  6. #include "stubbytes.h"
  7.  
  8. main(int argc, char **argv)
  9. {
  10.   int i;
  11.   for (i=1; i<argc; i++)
  12.     aout2exe(argv[i]);
  13. }
  14.  
  15. aout2exe(char *fname)
  16. {
  17.   int ifile;
  18.   int ofile;
  19.   char *ofname;
  20.   char buf[4096];
  21.   int rbytes;
  22.   ifile = open(fname, O_RDONLY|O_BINARY);
  23.   if (ifile < 0)
  24.   {
  25.     perror(fname);
  26.     return;
  27.   }
  28.   ofname = (char *)malloc(strlen(fname)+5);
  29.   sprintf(ofname, "%s.exe", fname);
  30.   ofile = open(ofname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
  31.   if (ofile < 0)
  32.   {
  33.     perror(ofname);
  34.     free(ofname);
  35.     return;
  36.   }
  37.   write(ofile, stub_bytes, sizeof(stub_bytes));
  38.   
  39.   while ((rbytes=read(ifile, buf, 4096)) > 0)
  40.   {
  41.     int wb = write(ofile, buf, rbytes);
  42.     if (wb < 0)
  43.     {
  44.       perror(ofname);
  45.       break;
  46.     }
  47.     if (wb < rbytes)
  48.     {
  49.       fprintf(stderr, "%s: disk full\n", ofname);
  50.       exit(1);
  51.     }
  52.   }
  53.   close(ifile);
  54.   close(ofile);
  55.   free(ofname);
  56. /*  remove(fname); */
  57. }
  58.